//
//  FindOfTableViewCell.m
//  A段项目
//
//  Created by dllo on 16/1/25.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "FindOfTableViewCell.h"
#import "Model.h"
#import <UIImageView+WebCache.h>
#import <DKNightVersion.h>

#define  WIDTH  [UIScreen mainScreen].bounds.size.width

@interface FindOfTableViewCell ()

@property (nonatomic, retain) UIImageView *imageForPic;
@property (nonatomic, retain) UILabel *label;
@property (nonatomic, retain) UILabel *title;
@property (nonatomic, retain) UILabel *backLabel;

@end

@implementation FindOfTableViewCell

- (void)dealloc {
    
    [super dealloc];
    
    [_imageForPic release];
    
    [_label release];
    
    [_title release];
    
    [_backLabel release];
    
    
}

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.imageForPic = [[UIImageView alloc] init];
        
        self.label = [[UILabel alloc] init];
        self.title = [[UILabel alloc] init];
        
        self.backLabel = [[UILabel alloc] init];
        
        [self.contentView addSubview:self.imageForPic];
        [self.contentView addSubview:self.label];
        [self.contentView addSubview:self.title];
        [self.contentView addSubview:self.backLabel];
        
        
        [_backLabel release];
        [_imageForPic release];
        [_label release];
        [_title release];
        
    }
    
    return self;
}

- (void)passedModel:(Model *)model {
    
    self.label.text = model.summary;
    self.title.text = model.title;
    [self.imageForPic sd_setImageWithURL:[NSURL URLWithString:model.coverUrl]];
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.imageForPic.frame = CGRectMake(5, 0,self.frame.size.width - 10, 200);
    self.title.frame = CGRectMake(10, 210, self.frame.size.width - 20, 20);
    
    self.imageForPic.layer.cornerRadius = 4;
    
    self.imageForPic.layer.masksToBounds = YES;

    self.title.font = [UIFont systemFontOfSize:18];
    self.label.frame = CGRectMake(10, 230, self.frame.size.width - 20, [[self class]heightForLabel:self.label.text]);
    
    self.backLabel.frame = CGRectMake(0, [[self class]heightForLabel:self.label.text] + 235, self.frame.size.width, 5);
    
    self.backLabel.backgroundColor = [UIColor grayColor];
    
    self.label.font = [UIFont systemFontOfSize:15];
    self.label.numberOfLines = 0;
    self.title.numberOfLines = 0;
    
    
   // self.backgroundColor = [UIColor colorWithRed:0.6 green:0.6 blue:0.4 alpha:0.8];
    
    self.dk_backgroundColorPicker = DKColorWithColors( [UIColor colorWithRed:0.6 green:0.6 blue:0.4 alpha:0.8], [UIColor colorWithRed:52 / 256.f green:52 / 256.f blue:52 / 256.f alpha:1]);
    
    self.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    
    self.title.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    
    
}


+(CGFloat)heightForLabel:(NSString *)text {
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(WIDTH - 20, 0) options:1 attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
    
    return rect.size.height;
    
}

+ (CGFloat)heightForCell:(Model *)model {
    
    CGFloat height = [FindOfTableViewCell heightForLabel:model.summary];
    
    return height + 220;
}











- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

@end
